// import Home from '@/views/Home'
// import VLogin from '@/views/Login'
// import Search from '@/views/Search'
// import VRegister from '@/views/Register'
// import GoodsDetail from '@/views/GoodsDetail'
// import AddCartSuccess from '@/views/AddCartSuccess'
// import ShopCart from '@/views/ShopCart'
// import VTrade from '@/views/Trade'
// import VPay from '@/views/Pay'
// import VCenter from '@/views/Center'
// import PaySuccess from '@/views/PaySuccess'
// 路由懒加载
const Home = () => import('@/views/Home')
const VLogin = () => import('@/views/Login')
const Search = () => import('@/views/Search')
const VRegister = () => import('@/views/Register')
const GoodsDetail = () => import('@/views/GoodsDetail')
const AddCartSuccess = () => import('@/views/AddCartSuccess')
const ShopCart = () => import('@/views/ShopCart')
const VTrade = () => import('@/views/Trade')
const VPay = () => import('@/views/Pay')
const VCenter = () => import('@/views/Center')
const PaySuccess = () => import('@/views/PaySuccess')
const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/login',
    component: VLogin,
    // 路由原信息
    meta: {
      isHidden: true
    }
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/register',
    component: VRegister,
    meta: {
      isHidden: true
    }
  },
  {
    path: '/goodsdetail/:id',
    component: GoodsDetail,
    meta: {
      name: 'gooddetail'
    }
    // 路由独享守卫
    // beforeEnter: (to, from, next) => {
    //   // 如果不写next的话就不能进入这个组件
    // }
  },
  {
    path: '/add_success',
    component: AddCartSuccess,
    // 加入购物车成功只能从详情进入
    beforeEnter(to, from, next) {
      if (from.meta.name === 'gooddetail') {
        next()
      } else {
        next('/login')
      }
    }
  },
  {
    path: '/shopcart',
    component: ShopCart
  },
  {
    path: '/trade',
    component: VTrade
  },
  {
    path: '/pay',
    component: VPay,
    beforeEnter(to, from, next) {
      if (from.path === '/trade') {
        next()
      } else {
        next('/login')
      }
    }
  },
  {
    path: '/center',
    component: VCenter
  },
  {
    path: '/paysuccess',
    component: PaySuccess,
    beforeEnter(to, from, next) {
      if (from.path === '/pay') {
        next()
      } else {
        next('/login')
      }
    }
  }
]
export default routes
